#define DEBUG
#include <cstdio>

using namespace std;

typedef long long ll;

const int maxn=300000, maxm=100000;

int main() {
    freopen("seq.in", "r", stdin);
    freopen("seq.out", "w", stdout);

    static int s[maxm+1];
    int n, m, k;
    scanf("%d", &m);
    for (int i=1; i<=m; i++) {
        scanf("%d", s+i);
    }

    static ll a[2];
    scanf("%d", &n);
    for (int i=1; i<=n; i++) {
        scanf("%lld %lld %d", a, a+1, &k);
        bool flag=false;
        ll maxv=a[0], minv=a[0];
        int maxa=-1, mina=-1;
        for (int j=1, p=1; j<=m; j++) {
            for (; p<=s[j]; p++) {
                ll t=a[0];
                a[0] = a[1];
                a[1] = k*a[1]+t;

                if (a[0]==0 && a[1]==0) break;

                if (a[0]<0 && a[1]<a[0] && a[0]<minv) {
                    mina = s[m];
                    if (maxa<0) maxa=s[1];
                    flag = true;
                    break;
                }
                if (a[0]>0 && a[1]>a[0] && a[0]>maxv) {
                    maxa = s[m];
                    if (mina<0) mina=s[1];
                    flag = true;
                    break;
                }
            }
            if (flag) break;
            if (j==1 || a[0]>maxv) {
                maxv = a[0], maxa=s[j];
            }
            if (j==1 || a[0]<minv) {
                minv = a[0], mina=s[j];
            }
            if (a[0]==0 && a[1]==0) break;
        }
        printf("%d %d\n", maxa, mina);
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
